<html>
<head>
    <title>审计-模型管理</title>
	<#include "/common/import.ftl" >
    <script type="text/javascript">
        $(function () {
            $('#modelList').datagrid({
                title: '审计模型列表',
                iconCls: 'icon-ok',
                url: '${ctx}/audit/model/model!data.action',
                striped: true,
                collapsible: false,
                fitColumns: true,
                pagination: true,
                singleSelect: true,
                rownumbers: true,
                remoteSort: false,
                pageList: [15, 20, 30, 50],
                idField: 'modelId',
                columns: [[
                    {field: 'modelCname', title: '名称', width: 100},
                    {field: 'modelEname', title: '英文全名称', width: 100},
                    {field: 'modelBussiness', title: '业务名称', width: 100},
                    {field: 'modelSysname', title: '系统名称', width: 100},
                    {field: 'modelRemark', title: '描述', width: 100}
                ]],
                toolbar: [{
                    text: '增加',
                    iconCls: 'icon-add',
                    handler: function () {
                        saveModel();
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        deleteModel();
                    }
                }, '-', {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        editModel();
                    }
                }, '-', {
                    text: '属性列表',
                    iconCls: 'icon-edit',
                    handler: function () {
                        unitList();
                    }
                }, '-', {
                    text: '刷新',
                    iconCls: 'icon-reload',
                    handler: function () {
                        $('#modelList').datagrid('reload');
                    }
                }]
            });
        });

        // 关闭添加、修改div
        function colseAdd() {
            $('#saveDiv').window('close');
        }

        // 刷新列表
        function reload() {
            $('#modelList').datagrid('reload');
        }

        // 增加应用系统
        function saveModel() {
            $('#saveFrame').html('');
            var url = '${ctx}/audit/model/add.action';
            $('#saveFrame').attr("title", '');
            $('#saveFrame').attr("src", url);
            $('#saveDiv').window('open');
        }

        // 修改应用系统
        function editModel() {
            var node = getSelected();
            if (node) {
                var url = '${ctx}/audit/model/add.action?id=' + node.modelId;
                $('#saveFrame').attr("title", node.itemText);
                $('#saveFrame').attr("src", url);
                $('#saveDiv').window('open');
            }
        }

        // 判断是否选中了需要操作的数据[修改、删除]
        function getSelected() {
            var selected = $('#modelList').datagrid('getSelected');
            if (selected) {
                return selected;
            } else {
                $.messager.alert('提示', '请选择要操作的数据', 'info');
            }
        }

        // 删除
        function deleteModel() {
            var node = getSelected();
            if (node) {
                $.messager.confirm('确认', '您确定要删除:<font color=red>' + node.modelCname + '</font> ？', function (r) {
                    if (r) {
                        $.ajax({
                            type: "post",
                            url: "${ctx}/audit/model/del.action?id=" + node.modelId,
                            success: function (data, textStatus) {
                                var result = jQuery.parseJSON(data);
                                if (result.flag == 'T') {
                                    $.messager.alert('结果', result.msg, 'info', function () {
                                        var rowIndex = $('#modelList').datagrid('getRowIndex', node);
                                        $('#modelList').datagrid('deleteRow', rowIndex);
                                    });
                                } else if (result.flag == 'H') {//删除提示先删除子列表
                                    $.messager.alert('结果', result.msg, 'info');
                                } else {
                                    $.messager.alert('结果', result.msg, 'error');
                                }
                            },
                            error: function () {
                                //请求出错处理
                            }
                        });
                    }
                });
            }
        }

        // 模块列表
        function unitList() {
            var node = getSelected();
            if (node) {
                $('#unitListFrame').html('');
                var url = '${ctx}/audit/modeldetail/list.action?modelId=' + node.modelId;
                $('#unitListFrame').attr("src", url);
                $('#unitListWin').window('open');
                $('#unitListWin').window('setTitle', '模型[<font color=red>' + node.modelCname + '</font>]属性管理');
            }
        }
    </script>
</head>
<body>
<!-- 应用列表 -->
<table id="modelList"></table>

<!-- 增加、修改窗口 -->
<div id="saveDiv" class="easyui-window" title="添加审计模型"
     style="padding:5px;width: 500px;height:350px;"
     iconCls="icon-search" closed="true" maximizable="false" minimizable="false"
     collapsible="false">
    <iframe frameborder="0" id="saveFrame" height="100%" width="100%" scrolling="auto"
            frameborder="0"></iframe>
</div>

<!-- 模块列表窗口 -->
<div id="unitListWin" class="easyui-window" title="审计属性管理"
     style="padding:5px;width:700px;height:400px;"
     iconCls="icon-search" closed="true" maximizable="false" minimizable="false"
     collapsible="false">
    <iframe frameborder="0" id="unitListFrame" height="100%" width="100%" scrolling="auto"
            frameborder="0"></iframe>
</div>
</body>
</html>